from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Category(models.Model):
    
    description = models.CharField(max_length=30, unique=True)
    user = models.ForeignKey(User)
    
    def __unicode__(self):
        return self.description

class Subcategory(models.Model):
    
    description = models.CharField(max_length=30)
    category = models.ForeignKey(Category)
    user = models.ForeignKey(User)
    
    def __unicode__(self):
        return self.description

class Mode(models.Model):
    
    description = models.CharField(max_length=30, unique=True)
    user = models.ForeignKey(User)
    
    def __unicode__(self):
        return self.description

class Spent(models.Model):
    description = models.TextField()
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    mode = models.ForeignKey(Mode)
    date = models.DateField()
    value = models.FloatField()
    user = models.ForeignKey(User)

    def __unicode__(self):
        return ' | '.join([self.description, 
                           repr(self.category), 
                                repr(self.mode), repr(self.date),
                                    repr(round(self.value,2))])

class Settings(models.Model):
    spentPerPage = models.IntegerField()
    user = models.ForeignKey(User)